package com.rui.common.base;

import com.rui.common.util.GenUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * entity基类
 *
 * @author xr
 * @email xr@qq.com
 * @date 2020-01-01 00:00:00
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final int is_delete_NORMAL = 0;
    private static final int is_delete_DELETE = 1;
    @ApiModelProperty("主键ID")
    @JsonSerialize(using= ToStringSerializer.class)
    protected Long id;
    @ApiModelProperty("创建者")
    @JsonSerialize(using= ToStringSerializer.class)
    protected Long createBy;
    @ApiModelProperty("创建时间")
    protected Date createDate;
    @ApiModelProperty("更新者")
    @JsonSerialize(using= ToStringSerializer.class)
    protected Long updateBy;
    @ApiModelProperty("更新时间")
    protected Date updateDate;
    @ApiModelProperty("删除标识")
    protected Integer delFlag;

    protected BaseEntity(Long id) {
        this.id = id;
    }

    public void prepareInsert() {
        this.id = GenUtil.genId();
//        this.createBy = UserUtil.getCurrentUser().getId();
//        this.updateBy = UserUtil.getCurrentUser().getId();
        this.createDate = new Date();
        this.updateDate = createDate;
        this.delFlag = is_delete_NORMAL;
    }

    public void prepareUpdate() {
//        this.updateBy = UserUtil.getCurrentUser().getId();
        this.updateDate = new Date();
    }

}